﻿using System;
using System.IO;
using FreeTextBoxControls;
using FreeTextBoxControls.Support;
using System.Collections;

namespace CommontLibrary
{
	/// <summary>
	/// Summary description for AddFreeTextBox.
	/// </summary>
	public class AddFreeTextBoxForum 
	{
		private string  RootImageDirectory="Attach/Forum/ImagesFreetextbox";
		protected FreeTextBoxControls.FreeTextBox FreeTextBox1=new FreeTextBox();		
		private ArrayList _AdditionalToolbars=new ArrayList();
		private SortedList _styles = new  SortedList();
		string requestPath="";
		public FreeTextBoxControls.FreeTextBox getFreeTextBox
		{
			get
			{
				
				return this.FreeTextBox1;
			}

		}
		public  void addToolBar()
		{			
			FreeTextBox1.Toolbars.Clear();
			FreeTextBox1.Toolbars.Add(AddStyleToolBar());
			FreeTextBox1.Toolbars.Add(AddColorToolBar());

			FreeTextBoxControls.Toolbar tb  = AddTextToolBar();
			if (tb.Items.Count > 0 )
			{
				FreeTextBox1.Toolbars.Add(AddTextToolBar());
			}

			FreeTextBox1.Toolbars.Add(AddFormatToolBar());
			FreeTextBox1.Toolbars.Add(AddEditToolBar());
			FreeTextBox1.Toolbars.Add(AddInsertToolBar());
			FreeTextBox1.Toolbars.Add(AddTableToolBar());
			FreeTextBox1.Toolbars.Add(AddSaveToolBar());	
			FreeTextBox1.ImageGalleryUrl =requestPath + "/ftb.imagegallery.aspx?cif=" + RootImageDirectory + "&rif=" + RootImageDirectory ;
			FreeTextBox1.SupportFolder ="Attach/";
			//FreeTextBox1.ToolbarStyleConfiguration = FreeTextBoxControls.ToolbarStyleConfiguration.OfficeXP;
		}
		public  void addToolBar(ref FreeTextBox  ftb)
		{			
			ftb.Toolbars.Clear();
			ftb.Toolbars.Add(AddStyleToolBar());
			ftb.Toolbars.Add(AddColorToolBar());

			FreeTextBoxControls.Toolbar tb  = AddTextToolBar();
			if (tb.Items.Count > 0 )
			{
				ftb.Toolbars.Add(AddTextToolBar());
			}

			ftb.Toolbars.Add(AddFormatToolBar());
			ftb.Toolbars.Add(AddEditToolBar());
			ftb.Toolbars.Add(AddInsertToolBar());
			ftb.Toolbars.Add(AddTableToolBar());
			ftb.Toolbars.Add(AddSaveToolBar());	
			ftb.ImageGalleryUrl ="ftb.imagegallery.aspx?cif=" + RootImageDirectory + "&rif=" + RootImageDirectory ;
			ftb.SupportFolder ="Attach/";
			//ftb.ToolbarStyleConfiguration = FreeTextBoxControls.ToolbarStyleConfiguration.OfficeXP;
		}
		public AddFreeTextBoxForum(string requestPath)
		{
			this.requestPath=requestPath;			
			//this.addToolBar();
			
		}
		public AddFreeTextBoxForum()
		{
			//this.addToolBar();
		}

		
		public FreeTextBoxControls.Toolbar  AddColorToolBar()
		{
			FreeTextBoxControls.Toolbar tb =new FreeTextBoxControls.Toolbar();
			tb.Items.Add(new FreeTextBoxControls.FontForeColorsMenu() );			
			tb.Items.Add(new FreeTextBoxControls.FontBackColorsMenu());
			tb.Items.Add(new FreeTextBoxControls.FontForeColorPicker());
			tb.Items.Add(new FreeTextBoxControls.FontBackColorPicker());

			return tb;
		}

		public FreeTextBoxControls.Toolbar  AddEditToolBar()
		{

			FreeTextBoxControls.Toolbar tb =new FreeTextBoxControls.Toolbar();
			tb.Items.Add(new FreeTextBoxControls.Cut());
			tb.Items.Add(new FreeTextBoxControls.Copy());
			tb.Items.Add(new FreeTextBoxControls.Paste());
			tb.Items.Add(new FreeTextBoxControls.Delete());
			tb.Items.Add(new FreeTextBoxControls.ToolbarSeparator());
			tb.Items.Add(new FreeTextBoxControls.Undo());
			tb.Items.Add(new FreeTextBoxControls.Redo());

			return tb;
		}
		 
		public FreeTextBoxControls.Toolbar  AddFormToolBar()
		{

			FreeTextBoxControls.Toolbar tb =new FreeTextBoxControls.Toolbar();
			tb.Items.Add(new FreeTextBoxControls.InsertForm());// 'pro only
			tb.Items.Add(new FreeTextBoxControls.InsertTextBox());// 'pro only
			tb.Items.Add(new FreeTextBoxControls.InsertTextArea());// 'pro only
			tb.Items.Add(new FreeTextBoxControls.InsertRadioButton());// 'pro only
			tb.Items.Add(new FreeTextBoxControls.InsertCheckBox());// 'pro only
			tb.Items.Add(new FreeTextBoxControls.InsertDropDownList());// 'pro only
			tb.Items.Add(new FreeTextBoxControls.InsertButton());// 'pro only
			tb.Items.Add(new FreeTextBoxControls.InsertDiv());// 'pro only

			return tb;

		}
		public FreeTextBoxControls.Toolbar  AddFormatToolBar()
		{

			FreeTextBoxControls.Toolbar tb =new FreeTextBoxControls.Toolbar();
			tb.Items.Add(new FreeTextBoxControls.JustifyLeft());
			tb.Items.Add(new FreeTextBoxControls.JustifyCenter());
			tb.Items.Add(new FreeTextBoxControls.JustifyRight());
			tb.Items.Add(new FreeTextBoxControls.JustifyFull());
			tb.Items.Add(new FreeTextBoxControls.ToolbarSeparator());
			tb.Items.Add(new FreeTextBoxControls.BulletedList());
			tb.Items.Add(new FreeTextBoxControls.NumberedList());
			tb.Items.Add(new FreeTextBoxControls.Indent());
			tb.Items.Add(new FreeTextBoxControls.Outdent());

			return tb;
		}

		public FreeTextBoxControls.Toolbar  AddInsertToolBar()
		{

			FreeTextBoxControls.Toolbar tb =new FreeTextBoxControls.Toolbar();
			tb.Items.Add(new FreeTextBoxControls.SymbolsMenu());
			tb.Items.Add(new FreeTextBoxControls.InsertRule());
			tb.Items.Add(new FreeTextBoxControls.InsertDate());
			tb.Items.Add(new FreeTextBoxControls.InsertTime());
			tb.Items.Add(new FreeTextBoxControls.ToolbarSeparator());
			tb.Items.Add(new FreeTextBoxControls.CreateLink());
			tb.Items.Add(new FreeTextBoxControls.Unlink());
			//tb.Items.Add(InsertSmiley());//khai bao o ben duoi
			tb.Items.Add(new FreeTextBoxControls.InsertImageFromGallery());			

			return tb;
		}
		public FreeTextBoxControls.StylesMenu AddStylesMenu()
		{ 			
			FreeTextBoxControls.StylesMenu styleMenu = new FreeTextBoxControls.StylesMenu();
			int i =-1;

			_styles = new SortedList();			

			//ParseStyleSheet(Server.MapPath("~/css/Admin.unicode.css"));
			ParseStyleSheet("css/Admin.unicode.css");

			for (i = 0 ; i<_styles.Count;i++)
			{
				FreeTextBoxControls.ToolbarListItem myListItem = new FreeTextBoxControls.ToolbarListItem() ;
				myListItem.Text = (string)_styles.GetByIndex(i);
				myListItem.Value = (string)_styles.GetKey(i);
				styleMenu.Items.Add(myListItem);
			}

			return styleMenu;

		}
		public void ParseStyleSheet(string strCssFile)
		{
//			if ( File.Exists(Server.MapPath(strCssFile) ))
//			{			
//				
//				
//				string[] styleDefinitions  = FreeTextBoxControls.Support.StyleSheetParser.ParseStyleSheet(strCssFile);
//
//				foreach( string styleDefinition in styleDefinitions)
//				{
//					//'First split single lines that contain multiple styles (separated by ",")
//					string[] styles  = styleDefinition.Split(',');
//					string style1="";
//					foreach (string style in styles)
//					{
//						//'First strip any white space
//						//style = HtmlUtils.StripWhiteSpace(style, False)
//						//'Next strip any :active, :hover, :link, :visited modifiers
//						style1 = style;
//						style1 = style1.Replace(":active", "");
//						style1 =style1.Replace(":hover", "");
//						style1 =style1.Replace(":link", "");
//						style1 =style1.Replace(":visited", "");
//
//						//'Next strip any leading "."
//						if (style.StartsWith(".") )
//						{
//							style1 = style1.Substring(1);
//						}
//						//'Only add styles that can apply to any content (ie do not add A.CommandButton etc)
//						if (style1.IndexOf(".") == -1 )
//						{
//							if (! _styles.ContainsKey(style1.ToLower()  ) )
//							{
//								_styles.Add(style1.ToLower(), style1);
//							}
//						}
//					}
//				}
//
//			}
		}

		public FreeTextBoxControls.Toolbar AddStyleToolBar()
		{

			FreeTextBoxControls.Toolbar tb =new FreeTextBoxControls.Toolbar();
			tb.Items.Add(AddStylesMenu());			
			tb.Items.Add(new FreeTextBoxControls.EditStyle());	
			tb.Items.Add(new FreeTextBoxControls.ParagraphMenu());
			tb.Items.Add(new FreeTextBoxControls.FontFacesMenu());
			tb.Items.Add(new FreeTextBoxControls.FontSizesMenu());	
			tb.Items.Add(new FreeTextBoxControls.InsertHtmlMenu());	
			

			return tb;

		}
		public FreeTextBoxControls.Toolbar AddTableToolBar()
		{	

			FreeTextBoxControls.Toolbar  tb = new FreeTextBoxControls.Toolbar();
			tb.Items.Add(new FreeTextBoxControls.InsertTable());
			tb.Items.Add(new FreeTextBoxControls.EditTable());
			tb.Items.Add(new FreeTextBoxControls.InsertTableColumnAfter());// 'pro only
			tb.Items.Add(new FreeTextBoxControls.InsertTableColumnBefore());// 'pro only
			tb.Items.Add(new FreeTextBoxControls.InsertTableRowBefore()); //'pro only
			tb.Items.Add(new FreeTextBoxControls.InsertTableRowAfter());// 'pro only
			tb.Items.Add(new FreeTextBoxControls.DeleteTableColumn());// 'pro only
			tb.Items.Add(new FreeTextBoxControls.DeleteTableRow()); //'pro only
		
			return tb;

		}
		public FreeTextBoxControls.Toolbar AddTextToolBar()
		{

			FreeTextBoxControls.Toolbar  tb = new FreeTextBoxControls.Toolbar();
			tb.Items.Add(new FreeTextBoxControls.Bold());
			tb.Items.Add(new FreeTextBoxControls.Italic());
			tb.Items.Add(new FreeTextBoxControls.Underline());
			tb.Items.Add(new FreeTextBoxControls.StrikeThrough());
			tb.Items.Add(new FreeTextBoxControls.SuperScript());
			tb.Items.Add(new FreeTextBoxControls.SubScript());
			tb.Items.Add(new FreeTextBoxControls.RemoveFormat());
			
			return tb;

		}

		public FreeTextBoxControls.Toolbar AddSaveToolBar()
		{

			FreeTextBoxControls.Toolbar  tb = new FreeTextBoxControls.Toolbar();
			tb.Items.Add(new FreeTextBoxControls.Preview());
			tb.Items.Add(new FreeTextBoxControls.Print());			
			tb.Items.Add(new FreeTextBoxControls.SelectAll());
			tb.Items.Add(new FreeTextBoxControls.NetSpell());
			tb.Items.Add(new FreeTextBoxControls.ToolbarSeparator());
			
		
			
			
			return tb;

		}


	}
}
